package com.jiayang.hhotel.presenter;

import com.jiayang.hhotel.bean.Constant;
import com.jiayang.hhotel.bean.SpecialRoomStateModel;
import com.jiayang.hhotel.net.Api;
import com.jiayang.hhotel.ui.SpecialRoomStateHisActivity;
import com.jiayang.hhotel.util.LogUtil;

import cn.droidlover.xdroidmvp.mvp.XPresent;
import cn.droidlover.xdroidmvp.net.ApiSubscriber;
import cn.droidlover.xdroidmvp.net.NetError;
import cn.droidlover.xdroidmvp.net.XApi;

/**
 * Created by Administrator on 2017/6/6 0006.
 * 特殊房态历史页面逻辑类
 */

public class SpecialRoomStateHisPresenter extends XPresent<SpecialRoomStateHisActivity> {

    public void getList(int mpLanguage,int mpOperation,int mpSerial,int page){
        Api.getHomeSer().getSpecialRoomList(Constant.PHONE,mpLanguage,mpOperation,mpSerial,page)
                .compose(XApi.<SpecialRoomStateModel>getApiTransformer())
                .compose(XApi.<SpecialRoomStateModel>getScheduler())
                .compose(getV().<SpecialRoomStateModel>bindToLifecycle())
                .subscribe(new ApiSubscriber<SpecialRoomStateModel>() {
                    @Override
                    protected void onFail(NetError error) {
                        LogUtil.showLog("请求错误="+error.getMessage());
                        getV().sealPic(error.getType());
                    }

                    @Override
                    public void onNext(SpecialRoomStateModel Model) {
                        LogUtil.showLog("特殊房态列表="+Model.toString());
                        switch (Model.getState()){
                            case 9://请求成功
                                getV().setAdapter(Model.getPAssignRoomListDtos());
                                break;
                            case -1://失败
                                getV().sealPic(-1);
                                break;
                            case 1002://没有数据
                                getV().sealPic(1002);
                                break;
                        }
                    }
                });
    }
}
